﻿using coremvcdemo.Code;
using coremvcdemo.Model;
using coremvcdemo.Model.DTO;
using coremvcdemo.Services;
using Microsoft.AspNetCore.Mvc;

namespace coremvcdemo.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [LoginFilter]
    public class RoleController : ControllerBase
    {
        private readonly IRoleService roleService;

        public RoleController(IRoleService roleService)
        {
            this.roleService = roleService;
        }
        /// <summary>
        /// 获取所有角色
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ActionResult<Dictionary<string, object>> getAllRole()
        {
            return roleService.getAllRole();
        }
        /// <summary>
        /// 插入菜单
        /// </summary>
        /// <returns></returns>
        [Route("~/api/Menu/Insert")]
        [HttpPost]
        public ActionResult<Dictionary<string, object>> InsertMenu(CoreDemo_B_菜单主表 PostData)
        {
            string Account=HttpContext.Session.GetString("code");
            return roleService.InsertMenu(PostData, Account);
        }
        /// <summary>
        /// 查询所有菜单
        /// </summary>
        /// <returns></returns>
        [Route("~/api/Menu/FindMenu")]
        [HttpGet]
        public ActionResult<Dictionary<string, object>> FindMenu()
        {
            return roleService.FindMenu();
        }
        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="menu"></param>
        /// <returns></returns>
        [Route("~/api/Menu/Delete")]
        [HttpPost]
        public ActionResult<Dictionary<string, object>> DeleteMenu(CoreDemo_B_菜单主表 menu)
        {
            return roleService.DeleteMenu(menu);
        }
        /// <summary>
        /// 更新菜单
        /// </summary>
        /// <returns></returns>
        [Route("~/api/Menu/Update")]
        [HttpPost]
        public ActionResult<Dictionary<string, object>> UpdateMenu(CoreDemo_B_菜单主表 PostData)
        {
            string Account = HttpContext.Session.GetString("code");
            return roleService.UpdateMenu(PostData, Account);
        }
        /// <summary>
        /// 新建角色
        /// </summary>
        /// <returns></returns>
        [Route("~/api/Role/Insert")]
        [HttpPost]
        public ActionResult<Dictionary<string, object>> InsertRole(RoleMenu roleMenu)
        {
            string Account = HttpContext.Session.GetString("code");
            return roleService.InsertRole(roleMenu, Account);
        }
        /// <summary>
        /// 新建角色
        /// </summary>
        /// <returns></returns>
        [Route("~/api/Role/GetRoleInfo")]
        [HttpGet]
        public ActionResult<Dictionary<string, object>> GetRoleInfo(string Id)
        {
            string Account = HttpContext.Session.GetString("code");
            return roleService.GetRoleInfo(Id);
        }
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [Route("~/api/Role/deleteRole")]
        [HttpPost]
        public ActionResult<Dictionary<string, object>> DeleteRole(CoreDemo_B_角色列表 role)
        {
            string Account = HttpContext.Session.GetString("code");
            return roleService.DeleteRole(role);
        }
        /// <summary>
        /// 获取权限
        /// </summary>
        /// <returns></returns>
        [Route("~/api/Role/GetAllPower")]
        [HttpGet]
        public ActionResult<Dictionary<string, object>> GetAllPower()
        {
            return roleService.GetAllPower();
        }
        /// <summary>
        /// 获取教师
        /// </summary>
        /// <returns></returns>
        [Route("~/api/role/GetAllUsing")]
        [HttpGet]
        public ActionResult<Dictionary<string, object>> GetAllUsing()
        {
            return roleService.GetAllUsing();
        }
        /// <summary>
        /// 获取部门
        /// </summary>
        /// <returns></returns>
        [Route("~/api/role/GetDeptUsing")]
        [HttpGet]
        public ActionResult<Dictionary<string, object>> GetDeptUsing()
        {
            return roleService.GetDeptUsing();
        }
        /// <summary>
        /// 根据卡号/教师获取部门
        /// </summary>
        /// <param name="para"></param>
        /// <returns></returns>
        [Route("~/api/role/GetUserByDeptAndCardNum")]
        [HttpPost]
        public ActionResult<Dictionary<string, object>> GetUserByDeptAndCardNum(PowerAddPara para)
        {
            return roleService.GetUserByDeptAndCardNum(para);
        }
        /// <summary>
        /// 设置权限
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [Route("~/api/role/SetRole")]
        [HttpPost]
        public ActionResult<Dictionary<string, object>> SetRole(PowerAddModel model)
        {
            string Account = HttpContext.Session.GetString("code");
            return roleService.SetRole(model, Account);
        }
        /// <summary>
        /// 删除权限
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [Route("~/api/Role/deletePower")]
        [HttpPost]
        public ActionResult<Dictionary<string, object>> deletePower(CoreDemo_B_人员权限 model)
        {
            string Account = HttpContext.Session.GetString("code");
            return roleService.deletePower(model);
        }
        /// <summary>
        /// 根据参数查询权限
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [Route("~/api/Role/getPowerInfoByParam")]
        [HttpPost]
        public ActionResult<Dictionary<string, object>> GetPowerInfoByParam(PowerManegePara para)
        {
            return roleService.GetPowerInfoByParam(para.Card, para.Name);
        }
        [Route("~/api/Role/UpdateRole")]
        [HttpPost]
        public ActionResult<Dictionary<string, object>> UpdateRole(RoleMenu roleMenu)
        {
            string Account = HttpContext.Session.GetString("code");
            return roleService.UpdateRole(roleMenu, Account);
        }
        [Route("~/api/Role/GetPersonMenu")]
        [HttpGet]
        public Task<Dictionary<string, object>> GetPersonMenu()
        {
            string Account = HttpContext.Session.GetString("code");
            return roleService.GetPersonMenu(Account);
        }
    }
}
